<template>
  <div class="td-doctor-me-appointment-item">
    <mt-header fixed title="预约项目设置">
      <router-link to="tdDoctorMe" slot="left">
        <mt-button icon="back"></mt-button>
      </router-link>
      <mt-button @click.native="btnEdit();" slot="right">新增</mt-button>
    </mt-header>

    <td-divider v-if="appointmentItemList.length===0" style="margin-top:100px;">暂无数据</td-divider>

    <div class="list" v-if="appointmentItemList.length!==0">
      <div class="appointment-item" v-for="(item,index) in appointmentItemList" :key="index">
        <mt-cell title="编号">
          <span>{{item.AppointmentItemID}}</span>
        </mt-cell>
        <mt-cell title="项目名称">{{item.ItemName}}</mt-cell>
        <mt-cell title="价格">{{utils$.subTransfer(item.ItemPrice)}}元</mt-cell>
        <mt-cell title="状态">
          <span v-if="item.ItemStatus===0">开启</span>
          <span v-if="item.ItemStatus===1">禁用</span>
        </mt-cell>
        <mt-cell title="操作">
          <span>
            <el-button size="mini" type="warning" @click="btnDelete(item);">删除</el-button>
            <el-button size="mini" type="primary" @click="btnEdit(item);">修改</el-button>
          </span>
        </mt-cell>
      </div>
    </div>
  </div>
</template>

<script>
import DoctorAppointmentItemService from "../../../../_services/doctorAppointmentItem.service";
export default {
  name: "TianDingDoctorMeAppointmentItemComponent",
  data() {
    return {
      user: {},
      appointmentItemList: []
    };
  },
  mounted() {
    this.user = this.utils$.dataFormat(
      JSON.parse(this.local$.getItem("tdUser"))
    );
    this.getAppointmentItemByDoctorID();
  },
  methods: {
    getAppointmentItemByDoctorID() {
      this.appointmentItemList = [];
      let params = {};
      params.doctorID = this.user.DoctorID;
      params.ItemStatus = 0;
      DoctorAppointmentItemService.getAppointmentItemByDoctorID(params).then(
        response => {
          if (response.Data.length > 0) {
            this.appointmentItemList = response.Data;
          }
        }
      );
    },
    btnEdit(item) {
      this.local$.removeItem("tdAppointmentItem");
      if (item !== undefined) {
        item.ItemPrice = this.utils$.subTransfer(item.ItemPrice);
        item.ItemStatus = item.ItemStatus.toString();
        this.local$.setItem("tdAppointmentItem", JSON.stringify(item));
      }
      this.$router.push({ name: "tdDoctorMeAppointmentItemEdit" });
    },
    btnDelete(item) {
      this.confirm$("提示", "确定要删除吗?", {
        confirm: action => {
          this.indicator$.open("请稍后...");
          let params = {};
          params.appointmentItemID = item.AppointmentItemID;
          params.doctorID = this.user.DoctorID;
          DoctorAppointmentItemService.deleteAppointmentItem(params).then(
            response => {
              if (response !== null && response.Data > 0) {
                this.toast$("删除成功");
              } else {
                this.toast$("删除失败");
              }
              this.indicator$.close();
              this.getAppointmentItemByDoctorID();
            }
          );
        }
      });
    }
  }
};
</script>

